package com.fanli.bigdata.mytest

import org.apache.spark._
import org.apache.spark.streaming._

/**
 * Created by liangdong.wu on 2016/11/25.
 */
object DsDemo {
  def main(args:Array[String]): Unit ={
    var conf = new SparkConf().setAppName("DSDEMO").setMaster("local[*]")
    var sc = new SparkContext(conf)
    var ssc = new StreamingContext(sc, Seconds(10))
    var lines = ssc.socketTextStream("115.159.45.213",9999)
    var words = lines.flatMap(_.split(" "))
    var pairs = words.map{word => (word,1)}
    var wordcounts = pairs.reduceByKey(_+_)
    wordcounts.print()
    ssc.start()
    ssc.awaitTermination()
  }
}